#include "math.h"
#include <algorithm>
#include <string>
#include <sstream>
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <sys/time.h>
#include <unistd.h>
#include "Matrix.h"
#include "nw_aligner_simple.cpp"


using namespace Numeric_lib;
using namespace std;

vector<string> &split(const string &s, char delim, vector<string> &elems) {
    stringstream ss(s);
    string item;
    while(getline(ss, item, delim)) {
        elems.push_back(item);
    }
    return elems;
}

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    return split(s, delim, elems);
}

int str2int(string str) {
    return atoi(str.c_str());
}


int main( int argc, char *argv[] ) {
    string input_line, genome, genome_id, gene, gene_id;
    vector<string> splited_str;
    double score;
    int start_pos, length;

    getline(cin, input_line);
    if (input_line.size() == 0) {
        return 0;
    }
    
    splited_str = split(input_line, '\t');
    if (splited_str.size() != 2) {
        cerr << "Bad genome line!" << endl;
        return 1;
    }
    genome_id = splited_str[0];
    genome    = splited_str[1];
    
    //Matrix<MICell, 2> matrix(10000, 10000);
    MICell* matrix = new MICell[(10000+1)*(10000+1)];

    while(cin) {
        getline(cin, input_line);
        if (input_line.size() == 0) {
            return 0;
        }
        splited_str = split(input_line, '\t');
        if (splited_str.size() != 3) {
            cerr << "Bad gene line!" << endl;
            return 1;
        }
        gene_id     = splited_str[0];
        start_pos   = str2int(splited_str[1]) - 1;
        gene        = splited_str[2];
        length      = gene.size();

        score = nw_score_mk(1, 3, 5, 2, genome.substr(start_pos, length), gene, matrix, 10);
        cout << genome_id << "\t" << gene_id << "\t" << score << endl;
    }

    return 0;

}
